<template>
    <span
      :class="`sw-button ${modelValue ? 'is-night' : ''} ${className}`"
      @click.capture="switchDayNight"
    >
      <span class="btnInner">
        <span class="bg0"></span>
        <span class="bg0 bg2"></span>
        <span class="clouds">
          <span v-for="ind in 5" :class="`cloud cloud${ind + 1}`" :key="ind + 'cloud'"></span>
        </span>
        <span class="planet">
          <span class="circleNight">
            <span class="crater"></span>
            <span class="crater crater2"></span>
            <span class="crater crater3"></span>
          </span>
        </span>
        <span class="clouds clouds2">
          <span v-for="ind in 5" :class="`cloud cloud${ind + 1}`" :key="ind + 'cloud'"></span>
        </span>
        <span class="night-stars">
          <span v-for="ind in 9" :class="`star star${ind + 1}`" :key="ind + 'star'">
            <svg
              version="1.1"
              :viewBox="'0 0 20 20'"
              height="20"
              width="20"
              style="width: 100%; height: 100%;"
            >
              <path
                d="M 0 10 c 5 0 10 -5 10 -10 c 0 5 5 10 10 10 c -5 0 -10 5 -10 10 c 0 -5 -5 -10 -10 -10"
                stroke="#fff"
                stroke-width="1"
                fill="#fff"
              />
            </svg>
          </span>
        </span>
        <span class="rocketBox">
          <span class="rocketInner">
            <svg version="1.1" viewBox="0 0 200 200">
              <g>
                <g>
                  <path
                    fill="#FFFFFF"
                    stroke="#000"
                    stroke-width="1.9843"
                    stroke-miterlimit="10"
                    d="M155.08,144.61l-3.13,10.29c0,0-1.57,2.85-9.34,0s-14.82-8.47-13.76-12.19c1.12-3.92,11.57-5.13,18.01-3.47    C155.08,141.37,155.08,144.61,155.08,144.61z"
                  />
                  <path
                    fill="#EE212A"
                    stroke="#000"
                    stroke-miterlimit="10"
                    d="M156.08,152.78l1.23-4.59c0,0,1.09-1.65,4.31-1.51c3.22,0.14,11.68,7.83,11.28,9.01    c-0.39,1.17-11.4,2.29-14.18,0.48C155.83,154.29,156.08,152.78,156.08,152.78z"
                  />
                  <path
                    fill="#E38F1C"
                    stroke="#000"
                    stroke-miterlimit="10"
                    d="M157.26,152.57l0.94-3.5c0,0,0.75-1.1,3.2-0.99s9,5.81,8.7,6.71c-0.3,0.9-8.72,1.58-10.84,0.2    C157.05,153.55,157.26,152.57,157.26,152.57z"
                  />
                  <path
                    fill="#F5F209"
                    stroke="#000"
                    stroke-miterlimit="10"
                    d="M157.53,152.11l0.76-2.82c0,0,1.15-0.5,2.15-0.43c2.03,0.14,7.28,4.35,7.03,5.09s-5.89,1.52-8.74-0.29    C157.91,153.14,157.53,152.11,157.53,152.11z"
                  />
                  <path
                    fill="none"
                    stroke="#000"
                    stroke-width="1.4173"
                    stroke-miterlimit="10"
                    d="M146.85,139.24c0,0-4.08,5.31-4.25,15.66"
                  />
                  <path
                    fill="#FF0000"
                    stroke="#000"
                    stroke-width="1.9843"
                    stroke-miterlimit="10"
                    d="M155.08,144.61l-3.13,10.29c0,0,1.25,1.71,3.13,1.27c1.34-0.32,4.31-9.88,3.52-11    C157.43,143.51,155.08,144.61,155.08,144.61z"
                  />
                </g>
              </g>
            </svg>
          </span>
        </span>
      </span>
    </span>
  </template>
  <script lang="tsx" setup name="DayNight">
//import type { SVGAttributes, ReservedProps } from 'vue';
//import type { JSX } from 'vue/jsx-runtime';

    const props = defineProps({
      modelValue: {
        type: Boolean,
        default: false,
      },
      className: {
        type: String,
        default: '',
      },
      restProps: {
        type: Object,
        default: () => ({}),
      },
    });
    const { modelValue, className } = props;
    const emit = defineEmits(['update:modelValue', 'dark-mode-changed']);
    const switchDayNight = () => {
      emit('update:modelValue', !props.modelValue);
      emit('dark-mode-changed', !props.modelValue);
    };
    defineExpose({ modelValue, className, switchDayNight });
    /*const Star = ({ color = '#fff' }: { color?: string }) => {
      const width = 20;
      const half = 10; //width/2;
      const quat = 5; //width/4;
      return (
        <svg
          version="1.1"
          viewBox={'0 0 ' + width + ' ' + width + ''}
          height={width}
          width={width}
          style={{
            width: '100%',
            height: '100%',
          }}
        >
          <path
            d={
              'M 0 ' +
              half +
              ' c ' +
              quat +
              ' 0 ' +
              half +
              ' -' +
              quat +
              ' ' +
              half +
              ' -' +
              half +
              ' c 0 ' +
              quat +
              ' ' +
              quat +
              ' ' +
              half +
              ' ' +
              half +
              ' ' +
              half +
              ' c -' +
              quat +
              ' 0 -' +
              half +
              ' ' +
              quat +
              ' -' +
              half +
              ' ' +
              half +
              ' c 0 -' +
              quat +
              ' -' +
              quat +
              ' -' +
              half +
              ' -' +
              half +
              ' -' +
              half +
              ''
            }
            stroke={color}
            stroke-width={1}
            fill={color}
          />
        </svg>
      );
    };
  /*  const baseAttr = {
      stroke: '#000',
      strokeMiterlimit: 10,
    };*/
/*
    const Head = (attr: JSX.IntrinsicAttributes & SVGAttributes & ReservedProps) => {
      const st7 = { fill: 'none', strokeWidth: 1.1339, ...baseAttr };
      const st11 = { fill: '#F5F4F5', ...baseAttr };
      const st12 = { fill: '#263753', ...baseAttr };
      const st13 = { fill: '#FFFFFF', strokeWidth: 0.8504, ...baseAttr };
      const st14 = { fill: '#D1D2D3' };
      return (
        <g {...attr}>
          <circle {...st11} cx="109.97" cy="47.67" r="24.76" />
          <path
            {...st7}
            d="M129.7,48.89c0,12.45-9.77,21.83-23.26,21.83c-11.34,0-20.83-9.38-20.83-21.83s9.19-22.54,20.53-22.54 S129.7,36.45,129.7,48.89z"
          />
          <path
            {...st12}
            d="M127.27,48.89c0,13.7-10.8,19.93-23.03,19.93c-10.28,0-18.62-8.92-18.62-19.93s8.34-19.93,18.62-19.93 S127.27,36.27,127.27,48.89z"
          />
          <ellipse {...st13} cx="132.12" cy="50.57" rx="6.65" ry="9.14" />
          <ellipse {...st13} cx="133.42" cy="50.81" rx="4.88" ry="7.29" />
          <path
            {...st14}
            d="M108.4,31.99c0,0-18.36,2.93-17.52,21.29C90.88,53.28,81.24,27.97,108.4,31.99z"
          />
          <ellipse {...st14} cx="119.26" cy="46.08" rx="3.48" ry="4.02" />
          <ellipse {...st14} cx="119.2" cy="53.64" rx="1.48" ry="1.74" />
        </g>
      );
    };*/
  </script>
  <style lang="scss">
    $btnW: 90px;
    $btnH: 40px;
    $paddingL: 2px;
    $time: 0.8s;
  
    @keyframes headAnimate {
      0% {
        transform: rotate(13deg);
      }
  
      10% {
        transform: rotate(13deg);
      }
  
      50% {
        transform: rotate(-15deg);
      }
  
      60% {
        transform: rotate(-15deg);
      }
  
      100% {
        transform: rotate(13deg);
      }
    }
  
    @keyframes humanAnimate {
      0% {
        transform: rotate(4deg);
      }
  
      40% {
        transform: rotate(-6deg);
      }
  
      50% {
        transform: rotate(-6deg);
      }
  
      90% {
        transform: rotate(4deg);
      }
  
      100% {
        transform: rotate(4deg);
      }
    }
  
    @keyframes flagAnimate {
      0% {
        transform: rotate(10deg);
      }
  
      50% {
        transform: rotate(-20deg);
      }
  
      100% {
        transform: rotate(10deg);
      }
    }
  
    .btnInner {
      transition: all $time ease-in-out;
      line-height: 0;
      display: inline-block;
      position: relative;
      height: $btnH;
      width: $btnW;
      border-radius: 100px;
      box-shadow: inset 0 2px 5px rgb(0 0 0 / 20%), 0 0 9px rgb(0 0 0 / 30%);
      overflow: hidden;
    }
  
    .bg0 {
      transition: all $time ease-in-out;
      display: inline-block;
      position: absolute;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      background: linear-gradient(to right, #9db8f7 0%, #4f77ce 100%);
      opacity: 100%;
  
      &.bg2 {
        background: linear-gradient(to right, #043789 30%, #020914 100%);
        opacity: 0;
      }
    }
  
    .planet {
      transition: all $time ease-in-out;
      position: absolute;
      overflow: hidden;
      width: $btnH - $paddingL - $paddingL;
      height: $btnH - $paddingL - $paddingL;
      top: $paddingL;
      left: $paddingL;
      background: #f6cf5b;
      border-radius: 100px;
      box-shadow: 0 0 3px rgb(255 255 255 / 60%), inset -0.5px -1px 3px rgb(0 0 0 / 30%),
        inset 1px 1px 3px rgb(255 255 255 / 50%);
  
      .circleNight {
        transition: all $time ease-in-out;
        transform: rotate(60deg) scale(1.7);
        opacity: 0;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-radius: 100px;
        background: #f1f1f1;
        box-shadow: 0 0 5px rgb(0 0 0 / 60%), inset -0.5px -1px 12px rgb(0 0 0 / 50%),
          inset 1px 1px 2px rgb(255 255 255 / 80%);
      }
  
      .crater {
        position: absolute;
        width: 25%;
        height: 25%;
        top: 12%;
        left: 44%;
        border-radius: 100px;
        background: #f1f1f1;
        box-shadow: inset $btnH * 0.042 $btnH * 0.042 $btnH * 0.065 rgb(12 8 146 / 19%),
          0 0 $btnH * 0.026 rgb(113 116 122 / 30%);
  
        &.crater2 {
          width: 34%;
          height: 34%;
          top: 42%;
          left: 16%;
        }
  
        &.crater3 {
          width: 19%;
          height: 19%;
          top: 62%;
          left: 63%;
          box-shadow: inset $btnH * 0.022 $btnH * 0.022 $btnH * 0.052 rgb(12 8 146 / 13%),
            0 0 $btnH * 0.02 rgb(113 116 122 / 30%);
        }
      }
    }
  
    .clouds {
      transition: all $time ease-in-out;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      opacity: 30%;
      transition-delay: 0s;
  
      &.clouds2 {
        transition-delay: $time * 0.2;
        opacity: 100%;
  
        .cloud {
          transform: scale(0.82);
  
          &.cloud2 {
            transform: scale(0.9);
            top: 60%;
            left: 62.5%;
          }
  
          &.cloud4 {
            transform: scale(0.75);
            top: 60%;
            left: 10%;
          }
  
          &.cloud5 {
            transform: scale(1);
            top: 74%;
            left: 62%;
          }
        }
      }
  
      .cloud {
        position: absolute;
        background: #fff;
        border-radius: 100px;
        width: $btnH * 0.8;
        height: $btnH * 0.8;
        top: 12%;
        left: 77%;
  
        &.cloud2 {
          width: $btnH * 0.55;
          height: $btnH * 0.55;
          top: 56%;
          left: 62%;
        }
  
        &.cloud3 {
          width: $btnH * 0.85;
          height: $btnH * 0.85;
          top: 42%;
          left: 32%;
        }
  
        &.cloud4 {
          width: $btnH * 0.9;
          height: $btnH * 0.9;
          top: 64%;
          left: 10%;
        }
  
        &.cloud5 {
          width: $btnH * 0.9;
          height: $btnH * 0.9;
          top: 60%;
          left: 70%;
        }
      }
    }
  
    .night-stars {
      transition: all $time * 0.5 ease-in-out;
      transition-delay: $time * 0.2;
      transform: scale(1.2);
      opacity: 0;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
  
      .star {
        display: inline-block;
        position: absolute;
        left: 28%;
        top: 13%;
        width: 4px;
        opacity: 80%;
  
        &.star2 {
          left: 10%;
          top: 35%;
          opacity: 100%;
          width: 6px;
        }
  
        &.star3 {
          left: 22%;
          top: 39%;
          width: 10px;
          opacity: 90%;
        }
  
        &.star4 {
          left: 13%;
          top: 75%;
        }
  
        &.star5 {
          left: 30%;
          top: 56%;
        }
  
        &.star6 {
          left: 43%;
          top: 31%;
          opacity: 80%;
        }
  
        &.star7 {
          left: 54%;
          top: 25%;
          width: 9px;
        }
  
        &.star8 {
          left: 41%;
          top: 79%;
          width: 6px;
        }
  
        &.star9 {
          left: 52%;
          top: 50%;
          width: 7px;
        }
      }
    }
    .rocketBox {
  width: 30px; /* 固定值或使用计算值 */
  transform: none;
}


    .rocketBox {
      width: $btnH * 0.8; /* 调整为更合理的比例 */
  top: 54%;
  left: 61%;
  transform: scale(1); /* 移除初始缩放 */
  opacity: 1;
  
      .rocketInner {
        display: inline-block;
        position: absolute;
        width: 100%;
        transition: all $time * 0.3 ease-in-out;
      }
    }
  
    .hand-flag {
      animation: flagAnimate 1s infinite;
      transform-origin: 59% 36%;
    }
    .humanBox, .human2 {
  transform: none; /* 移除初始变换 */
  width: $btnH * 0.6; /* 设置合理宽度 */
}

/* 夜间模式调整 */
.is-night {
  .rocketBox {
    top: -24%;
    left: -32%;
    transform: scale(0.6); /* 只在这里设置缩放 */
  }
  
  .humanBox {
    transform: rotateY(0deg); /* 只设置必要的变换 */
    opacity: 1;
  }
}
.rocketBox svg, .humanBox svg {
  width: 100%;
  height: auto;
}
    .head2 {
      transform: translate(-11%, 10%) rotate(-5deg) scale(3.2);
      transform-origin: 57% 30%;
    }
  
    .is-night {
      .bg0 {
        opacity: 0;
  
        &.bg2 {
          opacity: 100%;
        }
      }
  
      .planet {
        left: $btnW - $btnH + $paddingL;
  
        .circleNight {
          transform: rotate(0deg) scale(1);
          opacity: 100%;
        }
      }
  
      .clouds {
        top: 100%;
        transition-delay: $time * 0.2;
  
        &.clouds2 {
          transition-delay: 0s;
        }
      }
  
      .night-stars {
        transform: scale(1);
        opacity: 100%;
        transition-delay: $time * 0.7;
      }
  
      .rocketBox {
        top: -15%;
        left: -25%;
        transform: scale(0.5);
      }
    }
  
    .sw-button {
      display: inline-block;
      line-height: 0;
      cursor: pointer;
  
      &:hover {
        .rocketBox {
          .rocketInner {
            transform: translate(-6px, -3px);
          }
        }
      }
    }
  </style>
  
  